#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<bits/stdc++.h>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define out(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define VL vector<ll>
#define VVL vector<VL >
#define VC vector<char>
#define PI pair<int,int>
#define PL pair<ll,ll>
#define EPS 0.0000001


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

//#define INF 5340172838076674L
#define INF 1000000000
#define MOD 998244353

ll tr[400005],tad[400005],tmu[400005];
ll dat[100005];
int n,m;
ll p;

void pushup(int a,int b,int x){
  if(a==b)return;
  tr[x]=(tr[lson(x)]+tr[rson(x)])%p;
}
void build(int a,int b,int x){
  tmu[x]=1;
  if(a==b){
    tr[x]=dat[a]%p;
    return;
  }
  int mid=(a+b)/2;
  build(a,mid,lson(x));
  build(mid+1,b,rson(x));
  pushup(a,b,x);
}
void pushdown(int a,int b,int x){
  if(a==b)return;
  int mid=(a+b)/2;
  ll tmp;
  tmp=tmu[x];
  tmu[x]=1;
  tmu[lson(x)]=(tmu[lson(x)]*tmp)%p;
  tmu[rson(x)]=(tmu[rson(x)]*tmp)%p;
  tad[lson(x)]=(tad[lson(x)]*tmp)%p;
  tad[rson(x)]=(tad[rson(x)]*tmp)%p;
  tr[lson(x)]=(tr[lson(x)]*tmp)%p;
  tr[rson(x)]=(tr[rson(x)]*tmp)%p;
  tmp=tad[x];
  tad[x]=0;
  tad[lson(x)]=(tad[lson(x)]+tmp)%p;
  tad[rson(x)]=(tad[rson(x)]+tmp)%p;
  tr[lson(x)]=(tr[lson(x)]+(mid-a+1)*tmp)%p;
  tr[rson(x)]=(tr[rson(x)]+(b-mid)*tmp)%p;
  
}
void upd(int l,int r,int a,int b,int x,ll ad,ll mu){
  if(a>=l&&b<=r){
    tad[x]=(tad[x]*mu+ad)%p;
    tmu[x]=(tmu[x]*mu)%p;
    tr[x]=(tr[x]*mu)%p;
	tr[x]=(tr[x]+(b-a+1)*ad)%p;
    return ;
  }
  pushdown(a,b,x);
  int mid=(a+b)/2;
  if(l<=mid)upd(l,r,a,mid,lson(x),ad,mu);
  if(r>mid)upd(l,r,mid+1,b,rson(x),ad,mu);
  pushup(a,b,x);
}

ll que(int l,int r,int a,int b,int x){
  pushdown(a,b,x);
  if(a>=l&&b<=r){
    return tr[x];
  }
  ll res=0;
  int mid=(a+b)/2;
  if(l<=mid)res=que(l,r,a,mid,lson(x))%p;
  if(r>mid)res=(que(l,r,mid+1,b,rson(x))+res)%p;
  //cout<<' '<<l<<' '<<r<<' '<<a<<' '<<b<<' '<<res<<endl;
  return res;
}

int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
    memset(tr,0,sizeof tr);
    memset(tad,0,sizeof tad);
    n=read();m=read();p=read();
    for(int i=1;i<=n;i++)read(dat[i]);
    build(1,n,1);
    int a,b,c,d;
    for(int i=0;i<m;i++){
      d=read();
      if(d==1){
        a=read();b=read();c=read()%p;
        upd(a,b,1,n,1,0,c);
      }else if(d==2){
        a=read();b=read();c=read()%p;
        upd(a,b,1,n,1,c,1);
      }else{
        a=read();b=read();
        printf("%lld\n",que(a,b,1,n,1));
      }
    }
}